package com.sfac.javaSpringBoot.modules.test.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.sfac.javaSpringBoot.modules.common.entity.AbstractEntity;

import javax.persistence.*;

@Entity
@Table(name="test_card")
public class Card extends AbstractEntity {
    @Column(length = 50)//设置最大长度
    private String cardNo;
    /**
     * OneToOne：一对一关系中，有外键方使用 JoinColumn 注解，另一方使用 mappedBy 属性（可选）
     * cascade：联级操作
     * fetch：加载数据策略
     * JsonIgnore：不序列化该字段，避免无限递归
     */
    @OneToOne(mappedBy = "studentCard",cascade = CascadeType.ALL,fetch =FetchType.EAGER)
    @JsonIgnore//查看数据时，忽略此列，不需要将这里的student传递给前台，返回的数据不包含该属性
    private Student student;

    public String getCardNo() {
        return cardNo;
    }

    public void setCardNo(String cardNo) {
        this.cardNo = cardNo;
    }

    public Student getStudent() {
        return student;
    }

    public void setStudent(Student student) {
        this.student = student;
    }
}
